using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;

namespace EMRNotes
{
    public partial class EMRSearchForm : Form
    {
        private DirectoryInfo[] folders;
        
        public EMRSearchForm()
        {
            InitializeComponent();

            DirectoryInfo diSource = new DirectoryInfo((string)Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\MCD-soft\\OneNoteEMR", "EMRFolderPath", "C:\\Patients\\"));

            folders = diSource.GetDirectories();
        }

        public string EMRFolder { get; set; }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //openFileDialog1.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
  
            foreach (DirectoryInfo di in folders)
            {
                lbSearchResult.Items.Add(di.Name);
       
            }


        }

        private void lbSearchResult_SelectedValueChanged(object sender, EventArgs e)
        {
            EMRFolder = ((ListBox)sender).SelectedItem.ToString();
            if (EMRFolder != null && EMRFolder != String.Empty)
                btnOK.Enabled = true;
            //else
            //    btnOK.Enabled = false;
        }

        private void tbSearchString_TextChanged(object sender, EventArgs e)
        {
            
            lbSearchResult.Items.Clear();
            btnOK.Enabled = false;
            foreach (DirectoryInfo di in folders)
            {
                if (di.Name.ToLower().IndexOf(tbSearchString.Text.ToLower()) >= 0)                    
                    lbSearchResult.Items.Add(di.Name);
            }
        }

        private void lbSearchResult_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}